<!-- 3：实现类似挑选人的功能，
点击挑选按钮后，开始随机显示人名（提前定义在数组中）
再次点击按钮，停止运行，并显示被选中的人名，
要保证下次不会再次抽中此人 -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>点名器</title>
	</head>
	<body>
		<div>
			<p class="name"></p>
			<button onclick="start()">选择</button>
			<button onclick="stop()">停止</button>

		</div>
	</body>
	<script>
		var people = ["1", "2", "3", "4", "5", "6"];

		function selectPeople() {
			let name = document.querySelector(".name");

			let n = numb();
			name.innerHTML = people[n];
			return n;
		}

		function numb() {

			return parseInt(Math.random() * people.length);

		}

		var star;
		var peo;

		function start() {
			clearInterval(star);
			star = setInterval(function() {
				peo = selectPeople();
			}, 50);
		}

		function stop() {
			clearInterval(star);
			people.splice(peo, 1);
			console.log(people);
		}
	</script>
</html>
